//
//  HomeTabBar.m
//  LianMengPOC
//
//  Created by WangQi on 13-6-20.
//
//

#import "HomeTabBar.h"

@implementation HomeTabBar

- (id)initWithFrame:(CGRect)frame
{
    self = [super initWithFrame:frame];
    if (self) {
        // Initialization code
    }
    return self;
}

+ (HomeTabBar *)viewFromNib
{
    HomeTabBar *view = [[[NSBundle mainBundle] loadNibNamed:@"HomeTabBar" owner:self options:nil] objectAtIndex:0];
    return view;
}

- (void)selectTabBarAtIndex:(int)index
{
    UIButton *selectButton;
    switch (index) {
        case 0:
        {
            self.myApplicationButton.enabled = NO;
            self.phoneBankButton.enabled = YES;
            self.financialHelperButton.enabled = YES;
            selectButton = _myApplicationButton;
        }
            break;
        case 1:
        {
            self.myApplicationButton.enabled = YES;
            self.phoneBankButton.enabled = NO;
            self.financialHelperButton.enabled = YES;
            selectButton = _phoneBankButton;
        }
            break;
        case 2:
        {
            self.myApplicationButton.enabled = YES;
            self.phoneBankButton.enabled = YES;
            self.financialHelperButton.enabled = NO;
            selectButton = _financialHelperButton;
        }
            break;
        default:
            selectButton = _myApplicationButton;
            break;
    }
    [UIView animateWithDuration:0.3 animations:^{
         _selectImageView.center = selectButton.center;
    }];
   
}

- (void)dealloc {
    [_myApplicationButton release];
    [_phoneBankButton release];
    [_financialHelperButton release];
    [_selectImageView release];
    [super dealloc];
}

- (void)tapOnButtonIndex:(int)index
{
    [self selectTabBarAtIndex:index];
    if(_delegate && [_delegate respondsToSelector:@selector(homeTabBar:didSelectTabAtIndex:)]){
        [_delegate homeTabBar:self didSelectTabAtIndex:index];
    }
}

- (IBAction)tapOnMyApplicationButton:(id)sender
{
    [self tapOnButtonIndex:0];
}

- (IBAction)tapOnPhoneBankButton:(id)sender
{
    [self tapOnButtonIndex:1];
}

- (IBAction)tapOnFinancialHelperButton:(id)sender
{
    [self tapOnButtonIndex:2];
}



@end






